using UnityEngine;
using UnityEngine.SceneManagement;

public class TRIG_LEVELTRANSITION : MonoBehaviour
{
	public int LevelToGo;

	[Header("Multiplier, 1 = normal | 0.5 = half speed")]
	[SerializeField]
	private float TransitionSpeed = 1f;

	[SerializeField]
	private NewMainMenuManager.MainMenuStates TargetState = NewMainMenuManager.MainMenuStates.Hypothetical;

	[Header("-= Audio =-")]
	[SerializeField]
	private AudioClip PlaySoundOnTransition;

	[SerializeField]
	private float SoundVolume = 1f;

	private void OnTriggerEnter2D(Collider2D other)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)((Component)other).GetComponent<PlayerManager>()))
		{
			Scene activeScene = SceneManager.GetActiveScene();
			PlayerPrefs.SetInt("Game_PreviousVistedRoom", ((Scene)(ref activeScene)).buildIndex);
			BeginTransition(TransitionSpeed);
		}
	}

	public void BeginTransition(float Speed = 1f, bool UnpauseOnEnd = false)
	{
		if (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			ChatboxManager.Instance.EndText();
		}
		UI_FADE.Instance.StartFadeIn(LevelToGo, Speed, UnpauseOnEnd, TargetState);
		if ((Object)(object)PlaySoundOnTransition != (Object)null)
		{
			PlayerManager.Instance.PlayerAudioSource.PlayOneShot(PlaySoundOnTransition, SoundVolume);
		}
	}

	public void SimpleBeginTransition()
	{
		if (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			ChatboxManager.Instance.EndText();
		}
		UI_FADE.Instance.StartFadeIn(LevelToGo, TransitionSpeed, UnpauseOnEnd: false, TargetState);
		if ((Object)(object)PlaySoundOnTransition != (Object)null)
		{
			PlayerManager.Instance.PlayerAudioSource.PlayOneShot(PlaySoundOnTransition, SoundVolume);
		}
	}
}
